package com.lianxi.pojo.passport;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.SafeHtml;
import org.springframework.data.annotation.LastModifiedBy;

import javax.persistence.*;
import javax.validation.constraints.Min;
import java.io.Serializable;
import java.util.Date;

/**
 * @author yangzhenyu
 */
@Entity
@Table(name = "role")
@Data
@ApiModel(description = "角色实体")
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Role implements Serializable{


    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(nullable = false)
    @ApiModelProperty(name = "name",required = true,value = "角色名称")
    @NotBlank(message = "角色名称不能为空")
    @SafeHtml(message = "角色名称含有非法字符",whitelistType = SafeHtml.WhiteListType.NONE)
    private String name;

    @Column(name = "sn", length = 50)
    @ApiModelProperty(name = "sn",value = "sn")
    private String sn;

    @ApiModelProperty(name = "status",value = "状态")
    @Enumerated(EnumType.ORDINAL)
    @Column(columnDefinition = "tinyint")
    private Boolean status;

    @ApiModelProperty(name = "siteId",value = "系统id")
    @Column(name = "site_id",columnDefinition = "INT DEFAULT 0")
    @Min(value = 1, message = "请传入站点id")
    private int siteId;

    @ApiModelProperty(name = "siteName",value = "系统名字")
    @Column(name = "site_name")
    private String siteName;

    @Temporal(TemporalType.TIMESTAMP)
    @CreationTimestamp
    @ApiModelProperty(value = "创建时间")
    @Column(name = "create_time",updatable = false)
    private Date createTime;

    @Column(name = "create_user_name")
    @ApiModelProperty(value = "创建人姓名")
    private String createUserName;

    @ApiModelProperty(value = "创建用户id")
    @Column(name = "create_user_id",columnDefinition = "INT DEFAULT 0")
    @Min(0)
    private int createUserId;

    @ApiModelProperty(value = "最后修改时间")
    @UpdateTimestamp
    @Column(name = "modify_time")
    private Date modifyTime;

    @LastModifiedBy
    @ApiModelProperty(value = "最后修改人Id")
    @Column(name = "modify_user_id",columnDefinition = "INT DEFAULT 0")
    private int modifyUserId;

    @Column(name = "sign")
    protected String sign;
    /**
     * 基于SM3的
     */
    @Column(name = "key_cipher_str")
    protected String keyCipherStr;


    @Override
    public boolean equals(Object obj) {
        if(obj instanceof Role){
            Role temp = (Role) obj;
            return name.equals(temp.getName())&&temp.getId()==id;
        }
        return super.equals(obj);
    }
}
